package com.bdqn.t362.order.servlet;

import com.bdqn.t362.order.entity.TB2COrder;
import com.bdqn.t362.order.entity.TB2COrderLine;
import com.bdqn.t362.order.entity.TProduct;
import com.bdqn.t362.order.service.TB2COrderService;
import com.bdqn.t362.order.service.impl.TB2COrderServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author lqm
 * @ClassName ${NAME}
 * @description: 确认订单
 */
@WebServlet("/OrderConfirmServlet")
public class OrderConfirmServlet2 extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //订单明细
        List<TB2COrderLine> orderLines = new ArrayList<>();

        TB2COrderService tb2COrderService = new TB2COrderServiceImpl();
       //获取商品列表 service层
        List<TProduct> tempList = tb2COrderService.getProductList();
        for (int i = 0 ; i < tempList.size(); i++){
            TProduct tempEntity=tempList.get(i);
            //获取购物车提交的购买信息
            String productId=request.getParameter("productId_"+tempEntity.getId());
            String productNum=request.getParameter("productNum_"+tempEntity.getId());
            if(Integer.parseInt(productNum)>0){
                TB2COrderLine orderLine=new TB2COrderLine();
                orderLine.setId(Integer.parseInt(productId));
                orderLines.add(orderLine);
            }


        }

        //转发到确定订单页面
        request.setAttribute("list",orderLines);
        request.getRequestDispatcher("orderPay2.jsp");
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
